<?php
/**
 * 
 * 
 * @version $Id: Route.php 481 2012-11-04 02:19:24Z linsir123 $
 */
class Route 
{
	/**
	 * 商品
	 */
	static function urlItem($params)
	{
		$r = 'item/'. $params['iid'];
		///
		return lpUrl::__($r);
	}
	
	/**
	 * 商品(跳转)
	 */
	static function urlItemJump($params)
	{
		$r = 'item/jump/iid/'. $params['iid'];
		///
		return lpUrl::__($r);
	}
	
	/**
	 * 商店
	 */
	static function urlShop($params)
	{
		$r = 'shop/'. urlencode($params['nick']);
		///
		return lpUrl::__($r);
	}
	
	/**
	 * 商店(跳转)
	 */
	static function urlShopJump($params)
	{
		$r = 'shop/jump/nick/'. urlencode($params['nick']);
		///
		return lpUrl::__($r);
	}
	
	/**
	 * 分类(普通/折扣)
	 */
	static function urlClass($params)
	{
		if ( ! isset($params['pinyin'])) {
			$nav = M::nav()->getOne($params['cid']);
			$pinyin = empty($nav)?'search':$nav['pinyin'];
		} else 
			$pinyin = $params['pinyin'];
			
		///
		$type = empty($params['type'])?'list':$params['type'];
		$cId = empty($params['cid'])?0:$params['cid'];
		$keyword = empty($params['keyword'])?0:$params['keyword'];
		$sort = empty($params['sort'])?0:$params['sort'];
		$p = empty($params['p'])?0:$params['p'];
		$startPrice = empty($params['start_price'])?0:$params['start_price'];
		$endPrice = empty($params['end_price'])?0:$params['end_price'];
		
		///
		if ($type == 'list') 
			$r = sprintf("%s/%s/%s-%s-%s-%s-%s-%s",
				$type, $pinyin,
				$cId, urlencode($keyword),
				$startPrice, $endPrice, ///
				$sort, $p);
		else {
			if ($pinyin == 'search') {
				App::V('pinyin');
				$pinyin = string2pinyin($keyword);
			}
			
			$r = sprintf("%s/%s/%s-%s-%s-%s",
				$type, $pinyin,
				$cId, urlencode($keyword),
				$sort, $p);
		}
		
		///
		return lpUrl::__($r);
	}
	
	/**
	 * 天猫
	 */
	static function urlTmall($params)
	{
		$type = empty($params['type'])?'selected':$params['type'];
		$cId = empty($params['cid'])?0:$params['cid'];
		$p = empty($params['p'])?0:$params['p'];
		$pinyin = $params['pinyin'];
		
		///
		$r = sprintf("tmall/%s/%s/%s-%s", $type, $pinyin, $cId, $p);
		return lpUrl::__($r);
	}
	
	/**
	 * 淘宝图片“伪本地地址”
	 * // 将爬虫访问时的,图片全切换为本地图片
	 */
	static function urlPhoto($params)
	{
		static $init;
		if ( ! isset($init)) 
			$init = array(
				Request::isRobot(),
				App::getRequest()->domain .'images/logo.jpg',
			);
			
		///
		$url = $params['url'];
		$isShop = $params['shop'];
		list($isRobot, $default) = $init;
		if ($isRobot) 
			return $default;
			
		///
		return $isShop?('http://logo.taobaocdn.com/shop-logo'. $url):$url;
	}
}
